<%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %>
<%@page import="com.netscenery.yang.model.Enumeration"%>
<%@page import="com.netscenery.yang.model.Enum"%>
<%@page import="offer.GetDataSource"%>
<%@page import="offer.SessionObj"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Enumeration enumeration = new Enumeration();
//获取结点对象
Object itemNode = request.getAttribute("itemNode");
String StatusStr ="";
for(int i = 0 ; i < GetDataSource.getStatusList().length ; i ++){
	StatusStr += GetDataSource.getStatusList()[i] +"_";
}
StatusStr = StatusStr.substring(0, StatusStr.length()-1);
if( null != itemNode){
	enumeration = (Enumeration)itemNode;
}
SessionObj sessionObj = (SessionObj)request.getSession().getAttribute("sessionObj");
String control_disabled = "";
if(!sessionObj.getModuleStatus().toString().equalsIgnoreCase("EDITING")){
 control_disabled ="disabled='disabled'";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Enumeration</title>
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/items.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/subItems.css" />
    <script type="text/javascript"  src="<%=basePath%>jstree-v.pre1.0/_lib/jquery.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/index.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/EnumSupport.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/StringUtil.js"></script>
</head>
<body class="body">
 <form id="enumerationForm" method="post" action="<%=basePath %>EnumerationOpreateServlet" class="IndexFormStyle" >
   <input type="hidden"  id="nodeId" name="nodeId" value="<%=request.getAttribute("nodeId") %>"  readonly="readonly"/>
   <div id="TableContent" class="typeSubContent" >
      <div class="itemTitle">
          The Type [<%=enumeration.getClass().getSimpleName() %>] information 
      </div>
      &nbsp;Type name:&nbsp;<input class="inputText" id="enumeration_name" name="enumeration_name" value="<%=enumeration.getName() %>" readonly="readonly" /><br/><br/>
      <input type="hidden" id="enums_para" name="enums_para" value="" /><!-- 用于存放让参数 -->
      <input type="hidden" id="StatusStr" name="StatusStr" value="<%=StatusStr %>" /><!-- 用于存放Status数组-->
      <!-- ************Patterns Length Begin******************************************************************************** -->
      <div class="inContent">
        &nbsp;Enumeration:<input type="button" id="B_enumAdd" name="B_enumAdd" value="add" />
        <div id="EnumsContent" class="itemContent">
     	   <% for(int j = 0; j < enumeration.getEnumsNumber(); j++){ %>
     	   <% 	Enum itemEnum  = enumeration.getEnum(j); %>
     	   <div class="patternItem">
	            <div id="Enum_title" class="SubItemTitle">
	              <div class="patternLeft">Add Enum Item</div>
	              <div class="patternRight">
	                <a href="#" class="rangeRemove" onclick="enumDelete(this)" ><img class="buttonBcImg" width="20" src="<%=basePath%>/images/delete.png" /></a>
			     	<a href="#" class="rangeAdd" onclick="enumAdd()" ><img class="buttonBcImg" width="20" src="<%=basePath%>/images/add.png" /></a>
		     	  </div>
		     	  <div style="clear:both;"></div>
	            </div><!--  pattern_title end -->
	            <!-- ******************************************************************* --> 
	            <div id="EnumItemContainer" class="SubItemSContainer" >
		            <div class="itemDiv">
				       <span class="textSpan">&nbsp; name:</span>
				       <input class="inputText" id="enum_name" name="enum_name" value="<%=itemEnum.getName() %>"  />
				       <span class="notNullSpan">(*String)</span>
		  			</div>
					<div class="itemDiv">
					    <span class="textSpan">&nbsp;Value:</span>
					    <input class="inputText" id="enum_value" name="enum_value" value="<%=itemEnum.getValue() %>"  />
					    <!-- <span class="notNullSpan">(*Integer)</span>  -->
					</div>
				   	<div class="itemDiv">
				       <span class="textSpan">&nbsp;Status:</span>
				       <select style="width:305px;   height:23px;"   class="inputSelect" id="enum_status" name="enum_status">
				          <% for(int i = 0 ; i < GetDataSource.getStatusList().length ; i++ ){ %>
				          <% 	if(null != itemEnum.getStatus() && itemEnum.getStatus().getStatus().equalsIgnoreCase(GetDataSource.getStatusList()[i])  ){%> 	
				          			<option selected="selected"  value="<%= GetDataSource.getStatusList()[i]%>" ><%=GetDataSource.getStatusList()[i] %></option>  
				          <%	}else{ %>	
				                    <option  value="<%= GetDataSource.getStatusList()[i]%>" ><%=GetDataSource.getStatusList()[i] %></option>   
				         <% 	} 
				         	} %>
				       </select>
				    </div>
			   	    <span class="textSpan">&nbsp;Description:</span><br/>
			        <textarea class="intextArea"  id="enum_description" name="enum_description"><%=itemEnum.getDescription()==null?"":itemEnum.getDescription() %></textarea>
			   	    <span class="textSpan">&nbsp;Reference:</span><br/>
			        <textarea class="intextArea"  id="enum_reference" name="enum_reference"><%=itemEnum.getReference()==null?"":itemEnum.getReference() %></textarea>
		        </div>
           </div>
           <% } %>
        </div><!--  patternItemContent end -->
      </div><!-- inContent end  -->
      <!-- ************Patterns Length Begin******************************************************************************** -->
      
      
   </div>
   <div id="submitContent" class="submitContent">
     <input type="button" <%=control_disabled %> onclick="fromSubmit()" value="Apply"  />
   </div>
   </form>
 <script type="text/javascript">
     var StatusArr = document.getElementById("StatusStr").value;  //将Status的数组保存在js的全局变量中 
	 $(document).ready(function(){
	        if( $("div#EnumsContent").html().trim().length != 0){$("input#B_enumAdd").hide();}
	 		$("input#B_enumAdd").click(function(){enumAdd();});
	 	}
	 );
	 function fromSubmit(){
	    if(getEnumStr()){
	      document.getElementById("enumerationForm").submit();
	    }
	 }
 </script>
   
</body>
</html>